package com.zhuanzhuan.hero.user.helper;

import com.bj58.youpin.common.rpc.result.Result;
import com.bj58.youpin.common.utils.json.JsonUtils;
import com.zhuanzhuan.hero.biz.common.util.WxWarnTemplateUtil;
import com.zhuanzhuan.hero.search.facade.IHeroSearchUserFacade;
import com.zhuanzhuan.hero.search.module.dto.UserRegisterDTO;
import com.zhuanzhuan.hero.user.consts.Consts;
import com.zhuanzhuan.hero.user.enums.ExceptionMsgEnum;
import com.zhuanzhuan.hero.user.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ClassName HeroSearchHelper
 * @Description
 * @Author hanjunjun
 * @Date 2024/7/22 13:41
 */
@Component
@Slf4j
public class HeroSearchHelper {

    @Resource
    private IHeroSearchUserFacade heroSearchUserFacade;

    /**
     * 用户注册同步到es
     *
     * @param userRegisterDTO
     * @return boolean
     * @author  hanjunjun
     * @date 2024/7/22
     **/
    public boolean writeUser(UserRegisterDTO userRegisterDTO) {
        log.info("writeEsUser param={}", JsonUtils.toJsonWithoutNull(userRegisterDTO));
        Result<Boolean> result = heroSearchUserFacade.writeEsUser(userRegisterDTO);
        log.info("writeEsUser result={}", JsonUtils.toJsonWithoutNull(result));
        if (!result.isSuccess()) {
            log.error("writeEsUser失败");
            WxWarnTemplateUtil.warnOutInvokedService(Consts.SERVICE_NAME, Consts.SEARCH_SERVICE_NAME, "writeEsUser调用失败");
            throw new BusinessException(ExceptionMsgEnum.BUSINESS_ERROR);
        }

        return result.getData();
    }


}
